


#include <stdio.h>

struct ListNode 
{
    int val;
   struct ListNode* next;
};

typedef struct ListNode SLNode;

SLNode* hasCycle(struct ListNode* head)
{
    SLNode* slow = head;
    SLNode* fast = head;

    while (fast && fast->next)
    {
        slow = slow->next;
        fast = fast->next->next;
        if (slow == fast)
            return slow;
    }

    return NULL;
}

struct ListNode* detectCycle(struct ListNode* head)
{
    SLNode* meet = hasCycle(head);
    if (meet)
    {
        SLNode* pcur = head;
        while (pcur != meet)
        {
            pcur = pcur->next;
            meet = meet->next;
        }
        return pcur;
    }
    else
    {
        return NULL;
    }
}

int main(void)
{
    SLNode* head = NULL;
    detectCycle(head);

	return 0;
}